package com.zlp.enums;

import com.zlp.common.api.ResultCode;
import com.zlp.common.exception.CustomException;
import com.zlp.stategy.CouponSupplierStategy;
import com.zlp.stategy.impl.LhCouponSupplierStategyImpl;
import com.zlp.stategy.impl.YsCouponSupplierStategyImpl;
import com.zlp.utils.MethodUtil;
import com.zlp.utils.SpringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 供应商枚举工厂类型
 * @author ZouLiPing
 * @date 2022/8/17 10:27
 */
@Getter
@AllArgsConstructor
public enum SupplierFactoryEnum {

    LI_HAN("力翰",2000, LhCouponSupplierStategyImpl.class),

    YUNSHENG_FUTURE("云生未来",3000, YsCouponSupplierStategyImpl.class)
    ;
    private String name;
    private Integer code;

    /**
     *  公司
     */
    private Class<?> aClass;





    /**
     * getService
     */
    public static CouponSupplierStategy getService(Integer code) {
        for (SupplierFactoryEnum supplierFactoryEnum : SupplierFactoryEnum.values()) {
            if (supplierFactoryEnum.getCode().equals(code)) {
                return (CouponSupplierStategy) SpringUtils.getBean(supplierFactoryEnum.aClass);
            }
        }
        throw new CustomException(ResultCode.ARGUMENT_TYPE_MISMATCH, MethodUtil.getLineInfo());
    }

}